package cn.telling.telMarketCentre.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.telling.product.vo.ShopProductVo;
import cn.telling.telMarketCentre.dao.ITempsalerClearProductListDao;
import cn.telling.telMarketCentre.service.ITempsalerClearProductListService;

@Service("tempsalerClearProductListService")
public class TempsalerClearProductListServiceImpl implements ITempsalerClearProductListService {
	
	@Autowired
	@Qualifier("tempsalerClearProductListDao")
	private ITempsalerClearProductListDao tempsalerClearProductListDao;
	public ITempsalerClearProductListDao getTempsalerClearProductListDao() {
		return tempsalerClearProductListDao;
	}
	public void setTempsalerClearProductListDao(
			ITempsalerClearProductListDao tempsalerClearProductListDao) {
		this.tempsalerClearProductListDao = tempsalerClearProductListDao;
	}


	@Override
	public List<Map<String, String>> loadTempsalerClearProductList(String userId,String choose,String supplyId) {
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		List<Map<String, String>> tempsalerClearProductList = tempsalerClearProductListDao.loadTempsalerClearProductList(choose, supplyId);
		
		List<ShopProductVo> shopProductVoList = tempsalerClearProductListDao.getShopProductListNoPage(userId);
		List<String> shopProductVoProductIdList = new ArrayList<String>();
		if (shopProductVoList != null && shopProductVoList.size() > 0) {
			for(int i = 0; i < shopProductVoList.size(); i++) {
				shopProductVoProductIdList.add(String.valueOf(shopProductVoList.get(i).getProductId()));
			}
		}
		
		if(tempsalerClearProductList != null && tempsalerClearProductList.size() > 0){
			for(int i = 0; i < tempsalerClearProductList.size(); i++){
				Map<String,String> tmp = tempsalerClearProductList.get(i);
				if(!shopProductVoProductIdList.contains(tmp.get("productId"))){
					list.add(tmp);
				}
			}
		}
		return list;
	}

}
